package com.jprocms.module.cms.controller.portal.api;

import com.jpro.framework.common.pojo.CommonResult;
import com.jpro.framework.common.util.object.BeanUtils;
import com.jprocms.module.cms.controller.admin.imgblock.vo.ImgblockRespVO;
import com.jprocms.module.cms.dal.dataobject.imgblock.ImgblockDO;
import com.jprocms.module.cms.service.imgblock.ImgblockService;
import com.jprocms.module.cms.service.site.SiteService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import static com.jpro.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.jprocms.module.cms.constant.CmsSysConstants.FRONT_API;
import static com.jprocms.module.cms.enums.ErrorCodeConstants.IMGBLOCK_NOT_EXISTS;

/**
 * 飘窗 Controller
 *
 * @author jprocms
 */
@Tag(name = "飘窗接口", description = "飘窗接口")
@RestController
@RequestMapping({FRONT_API + "/imgblock"})
public class ImgblockApiController {
    private final ImgblockService service;
    private final SiteService siteService;

    public ImgblockApiController(ImgblockService service, SiteService siteService) {
        this.service = service;
        this.siteService = siteService;
    }

    @Operation(summary = "获取飘窗详情")
    @ApiResponses(value = {@ApiResponse(description = "获取飘窗详情")})
    @GetMapping("/{id:[\\d]+}")
    public CommonResult<ImgblockRespVO> getDetail(@Parameter(description = "获取飘窗详情ID") @PathVariable Long id) {
        ImgblockDO bean = service.getImgblock(id);
        if (bean == null) {
            throw exception(IMGBLOCK_NOT_EXISTS);
        }
        return CommonResult.success(BeanUtils.toBean(bean,ImgblockRespVO.class));
    }

}
